﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace DownloadFiles
{
    public partial class AddFileForm : Form
    {
        internal Action<List<KeyValuePair<string, string>>> AddFileCallback { get; set; }

        public AddFileForm()
        {
            InitializeComponent();
        }

        protected const string SelectPathKey = "DownloadFiles.AddFileForm.SelectPath.config";

        public string SelectPath
        {
            get
            {
                try
                {
                   return File.ReadAllText(Path.Combine(Path.GetTempPath(), SelectPathKey));
                }
                catch (Exception)
                {
                    return null;
                }   
            }
            set
            {
                try
                {
                     File.WriteAllText(Path.Combine(Path.GetTempPath(), SelectPathKey),value);
                }
                catch (Exception)
                {
                }
            }
        }
        protected virtual void AddFileComplete(List<KeyValuePair<string, string>> data)
        {
            if (AddFileCallback != null && data != null)
            {
                AddFileCallback(data);
            }
            this.Close();
        }

        protected virtual void CloseForm()
        {
            this.Close();
        }

        protected virtual bool IsUrl(string url)
        {
            string pattern = @"(http|ftp|https):\/\/[\w]+(.[\w]+)([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])";
            return Regex.IsMatch(url, pattern);

        }

        //protected void btnClose_Click(object sender, EventArgs e)
        //{
        //    CloseForm();
        //}
    }
}
